package netmorph.model.parts;

import java.util.Locale;

import javax.swing.table.DefaultTableModel;

import netmorph.model.NetmorphModel;


public class BESInputModel extends DefaultTableModel {

	static Locale l = Locale.US; // for "12.3456" formatting
	
	static String[] params = new String[] {
		"all_dendrites.B_inf", "all_dendrites.E", "all_dendrites.S", "all_dendrites.tau", 
		"pyr1.oblique.B_inf", "pyr1.oblique.E", "pyr1.oblique.S", "pyr1.oblique.tau", 
		"pyr1.tuft.B_inf", "pyr1.tuft.E", "pyr1.tuft.S", "pyr1.tuft.tau" 
		};
	NetmorphModel model;

	public double getBasalB()   { return Double.parseDouble((String)getValueAt(0, 1)); }
	public double getBasalE()   { return Double.parseDouble((String)getValueAt(1, 1)); }
	public double getBasalS()   { return Double.parseDouble((String)getValueAt(2, 1)); }
	public double getObliqueB() { return Double.parseDouble((String)getValueAt(4, 1)); }
	public double getObliqueE() { return Double.parseDouble((String)getValueAt(5, 1)); }
	public double getObliqueS() { return Double.parseDouble((String)getValueAt(6, 1)); }
	public double getTuftB()    { return Double.parseDouble((String)getValueAt(8, 1)); }
	public double getTuftE()    { return Double.parseDouble((String)getValueAt(9, 1)); }
	public double getTuftS()    { return Double.parseDouble((String)getValueAt(10, 1)); }
	
	public void setBasalB(double b)   { setValueAt(String.format(l, "%.5f", b), 0, 1); }
	public void setBasalE(double e)   { setValueAt(String.format(l, "%.5f", e), 1, 1); }
	public void setBasalS(double s)   { setValueAt(String.format(l, "%.5f", s), 2, 1); }
	public void setObliqueB(double b) { setValueAt(String.format(l, "%.5f", b), 4, 1); }
	public void setObliqueE(double e) { setValueAt(String.format(l, "%.5f", e), 5, 1); }
	public void setObliqueS(double s) { setValueAt(String.format(l, "%.5f", s), 6, 1); }
	public void setTuftB(double b)    { setValueAt(String.format(l, "%.5f", b), 8, 1); }
	public void setTuftE(double e)    { setValueAt(String.format(l, "%.5f", e), 9, 1); }
	public void setTuftS(double s)    { setValueAt(String.format(l, "%.5f", s), 10, 1); }
	
	public BESInputModel(NetmorphModel model) {
		this.model = model;
	}
	
	@Override
	public int getColumnCount() {
		return 2;
	}
	 
	@Override
	public int getRowCount() {
		return params.length;
	}
	
	@Override
	public String getColumnName(int column) {
		return new String[] { "Input Variable", "Value" }[column];
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		return column==1;
	}
	
	@Override
	public Object getValueAt(int row, int column) {
		String pname = params[row]; 
		if (column == 0) { return pname; } 
		else { return model.getParam(pname); }
	}
	
	@Override
	public void setValueAt(Object aValue, int row, int column) {
		String pname = params[row]; 
		if (column == 0) { return; } 
		else { model.setParam(pname, (String)aValue); }
	}
}
